package com.itheima.reggie.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * MP配置类
 *
 * @Author Vsunks.v
 * @Date 2022/8/11 10:03
 * @Blog blog.sunxiaowei.net/996.mba
 * @Description: MP配置类
 */
@Configuration
public class MybatisPlusConfig {

    // 装配分页插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        // 创建MP插件
        MybatisPlusInterceptor mbpi = new MybatisPlusInterceptor();

        // 创建分页插件
        PaginationInnerInterceptor itc = new PaginationInnerInterceptor();

        // 分页参数合理化，当页码超过范围后，自动查询最后一页
        itc.setOverflow(true);

        // 添加分页插件到mp插件
        mbpi.addInnerInterceptor(itc);
        return mbpi;
    }
}
